<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    td{width: 50px;}
    th{background-color: beige;}
    table{padding: 0 20px;float: left;}
  </style>
</head>
<body>
  
  <script>
    var array = ['日','一','二','三','四','五','六'];
    var table = document.createElement("table");
    var tr = document.createElement("tr");
    
    //函数调用
    createTh(tr,7,array);
    var tr1 = document.createElement("tr");
    createTdOrTr(tr1,7,"tr");
    table.appendChild(tr);
    table.appendChild(tr1);
    document.body.appendChild(table);

    //1.自定义函数，实现创建num个th的功能
    function createTh(ele,num,arr){
      for(let i=0;i<num;i++){
        var th = document.createElement("th");
        th.innerHTML = arr[i];
        ele.appendChild(th);
      }
    }
    //2.自定义函数，实现创建num个td的功能
    function createTdOrTr(ele,num,type){
      for(let i=0;i<num;i++){
        var th = document.createElement(type);        
        ele.appendChild(th);
      }
    }

  </script>
  
</body>
</html>